function C=htmltable2cell(T)

%HTMLTABLE2CELL a cell array with the contents of a HTML table
%Syntax: C=htmltable2cell(T)
%Description: T is text with the HTML tags for a table somewhere
%in there. This function will create a cell array with the contents of the
%table cells.
%
%Jonas Almeida 2008 January 17

m=length(regexpi(T,'<tr>(.*?)</tr>','tokens')); %number of rows
TD=regexpi(T,'<td>(.*?)</td>','tokens');n=length(TD)/m; %number of columns
C=cell(n,m); % since the cells will be filled linearly we need teh cell array sideways
C(:)=[TD{:}]; %Fill it with contents of TD, remember the arrays is sideways in next linebr

%here we need to see if there are duplicate headers as this will break the
%struct when creating as there can only be one name. As such if there are
%dups add '_' and a number which will be incremented as it requires.
C = find_dup(C);
C=cell2struct(C(:,2:end),C(:,1),1); %return it as a structure, fields named using the first row



